/*------------------------------------------------------------------------------------------------
*------------------------------------------------------------------------------------------------
"Descriptive results HFS & SEIC.do" this code produces nearly all figures referenced in Section 6 
"Descriptive evidence on donor characteristics and motives." (Table 1, Table 2, Appendix Table A5, 
Appendix Figure A2, Appendix Figure A3, Appendix Table A6). Only Figure 5 is not part of this code 
because it is based on the SafeGraph data and not the HFS and SEIC surveys. 
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------ */

clear

/*-------------------------------------------
Global pahts to import the data.
-------------------------------------------*/

global cd ""  //Set the path to the root folder ending in RFSDelivery
global path_md "${cd}/Data/IRSFFA/Sample" // input HFS data
global path_prt "${cd}/Results/Tables/IRSFFA" // output tables
global path_prf "${cd}/Results/Figures/IRSFFA" // output figures
global ttype "csv"  // change to "tex" if you want tex instead of "csv" outputs
global toptions  // can be either empty or booktabs depending on whether ttype is csv or tex respectively.


/*-------------------------------------------
Import the data.
-------------------------------------------*/
* This is the HFS and SEIC survey data (stacked) which is not publicly available. We do not have the right to disseminate it. Contact the Social Policy Institute at WashU for access. 
use "${path_md}/irsffa_cleaned_sample.dta" , replace 


/*-------------------------------------------
Data cleaning and variable generation
-------------------------------------------*/
*Generate some group variables
gen year = yearf
egen yw = group(year wave)
egen stateg = group(state_abbrev)
egen countyg = group(county)
egen county_wave = group(county wave)
egen cbsa_year = group(cbsa year)
egen cbsa_wave = group(cbsa wave)
egen state_year = group(stateg year)
egen state_wave = group(stateg wave)
egen health_insuranceg = group(health_insurance)
label var year "Year"
label var wave "Wave"
label var stateg "State"
label var state_year "State \(\times\) Year"
label var state_wave "State \(\times\) Wave"
label var cbsa_year "CBSA \(\times\) Year"
label var yw "Year-Wave"

gen sample=1

gen antiplasma = 1 - plas_any if (plas_any!=.)
label var plas_any "Plasma"

*Fix up some of the labels (for consistency)
gen children_gt0 = (children>0) if (children!=.)
gen children_gt1 = (children>1) if (children!=.)
gen children_gt2 = (children>1) if (children!=.)
label var children "Children"
label var children_gt1 "Children gt1"
label var children_gt2 "Children gt2"
label var children_gt0 "Children Any"

gen children_sq = children ^ 2 if (children!=.)
label var children_sq "Children^2"
gen age_sq = age ^ 2
label var age_sq "Age sq."

gen singleparent = 0 if (married!=.)&(children!=.)
replace singleparent = 1 if (married==0)&(children>0)
label var singleparent "Single Parent"


gen age_cat_d = 1*(age>23) + 1*(age>29) + 1*(age>43)
gen age_lt23 = 1*(age<23) if age!=.
gen age_23to28 = 1*((age>=23)&(age<=28)) if age!=.
gen age_29to42 = 1*((age>=29)&(age<=42)) if age!=.
gen age_gt42 = 1*(age>42) if age!=.
gen age_gt35 = 1*(age>35) if age!=.
label var age_gt35 "Age gt35"
gen age_lte45 = 1*(age<=45) if age!=.
label var age_lte45 "Age lte45"
gen age_lte40 = 1*(age<=40) if age!=.
label var age_lte40 "Age lte40"
gen age_lte35 = 1*(age<=35) if age!=.
label var age_lte35 "Age lte35"
gen age_lte30 = 1*(age<=30) if age!=.
label var age_lte30 "Age lte30"

gen hhinc_lt25k_c = hhinc_lt10k + hhinc_lt15k + hhinc_lt25k 
gen hhinc_lt50k_c = hhinc_lt25k_c + hhinc_lt35k + hhinc_lt50k

gen student_ft = 1*(student==2) if student!=.
gen student_pt = 1*(student==1) if student!=.
label var student_ft "Student FT"
label var student_pt "Student PT"
cap drop student_s
gen student_s = 1*(student>0) if student!=.
label var student_s "Student"


gen male = 1*(gender=="Male") if gender!=""
gen emp_ft = 1*(employ==0) if employ!=.
gen emp_pt = 1*(employ==3) if employ!=.
gen emp_ue = 1*(employ==4) if employ!=.
label var male "Male"
label var emp_ft "Employed FT"
label var emp_pt "Employed PT"
label var emp_ue "Unemployed"

gen plas_numcp = plas_numc if (plas_numc>0)&(plas_numc!=.)
label var plas_numcp "Plasma Num"

* create indicator for each survey wave/year combination
gen s1819 = 1*(year<2021)&(year>2017)
gen s21 = 1*(year==2021)
gen s21w1 = 1*(year==2021)&(wave==1)
gen s21w2 = 1*(year==2021)&(wave==2)
gen s21w3 = 1*(year==2021)&(wave==3)
gen s21w4 = 1*(year==2021)&(wave==4)
gen s21w5 = 1*(year==2021)&(wave==5)

gen bach = 0 if (educs!="")
replace bach = 1 if (educs=="bach")|(educs=="grad")
label var bach "Bachelor's or higher"

gen cbsad = 1*(cbsa<99999) if cbsa!=.

cap drop plasma_ind50_500 
egen plasma_ind50_500 = rowtotal(plasma_ind50 plasma_ind100 plasma_ind250 plasma_ind500)

*Adjust the deciles to something easier to display.
replace fin_income_q10 = fin_income_q10 +1 
replace pop2sqkm_wq10 = pop2sqkm_wq10 +1

gen s1819w1 = 1*(year<2021)&(wave==1)
gen s1819a30 = 1*(year<2021)&(age_lte30==1) 
gen s1819a35 = 1*(year<2021)&(age_lte35==1)
gen s1819a40 = 1*(year<2021)&(age_lte40==1)
gen s1819a45 = 1*(year<2021)&(age_lte45==1)
gen s1819s1 = 1*(year<2021)&(shock_any==1) if shock_any!=.
gen s1819inc = 1*(year<2021)&(fin_income_q10>5) if fin_income_q10!=.
gen s1819bach = 1*(year<2021)&(bach==1) if bach!=.


/* deal with weird coding of plasma frequency variable*/
tab plas_num yearf if yearf<2021 & plas_any==1
// since the question is predicated on having sold plasma at least once in the last 6 months, change zeros to 1
replace plas_numc = . if plas_any==0
replace plas_numc=1 if plas_any==1 & plas_numc==0
// 2018 survey was categoricial with more than 10 times set to 11 (2019 survey was continuous), must clip at 11 to make the two surveys comparable

gen plas_gt1 = 1*(plas_numc>1) if plas_any!=.
gen plas_gt2 = 1*(plas_numc>2) if plas_any!=.
gen plas_gt6 = 1*(plas_numc>6) if plas_any!=.
label var plas_gt1 "PC gt1"
label var plas_gt1 "PC gt2"
label var plas_gt6 "PC gt6"
replace plas_numc = . if plas_any==.
gen afs_kite = hard_kite
label var afs_kite "AFS Overdraft"

cap drop rm socdis_safety_mean
egen rm = rowmiss(socdis_mask socdis_inform socdis_wash socdis_gather socdis_distance socdis_home)
egen socdis_safety_mean = rowmean(socdis_mask socdis_inform socdis_wash socdis_gather socdis_distance socdis_home) if rm<2
label var socdis_safety_mean "SocDis Safety"
cap drop rm 

gen fl_lt_q2 = 1*(fl_lt_q3>0) if fl_lt_q3 != .
gen fa_lt_q2 = 1*(fa_lt_q3>0) if fa_lt_q3 != .
gen fl_lt_q2l = 1*(fl_lt_q2==0) if fl_lt_q2 != .
gen fa_lt_q2l = 1*(fa_lt_q2==0) if fa_lt_q2 != .
label var fl_lt_q2l "Fin Liab LT Low"
label var fa_lt_q2l "Fin Asset LT Low"
gen fa_st_q3l = 1*(fa_st_q3==0) if fa_st_q3!=.
gen fa_st_q3m = 1*(fa_st_q3==1) if fa_st_q3!=.
gen fl_st_q3l = 1*(fl_st_q3==0) if fl_st_q3!=.
gen fl_st_q3m = 1*(fl_st_q3==1) if fl_st_q3!=.
label var fl_st_q3l "Fin Liab ST Low"
label var fa_st_q3l "Fin Asset ST Low"
label var fl_st_q3m "Fin Liab ST Mid"
label var fa_st_q3m "Fin Asset ST Mid"

* sum short and long term liabilities together since that break out is overly complicated
egen liab = rowtotal(fl_lt fl_st) // sum short and long term liab together
sort yearf wave
by yearf wave: egen liab_q3 = xtile(liab) if !missing(liab), nq(3)   
g liab_q3_low = (liab_q3==1)
g liab_q3_mid = (liab_q3==2)
g liab_q3_high = (liab_q3==3)
label var liab_q3_low "Low Liabilities"
label var liab_q3_mid "Mid Liabilities"
label var liab_q3_high "High Liabilities"

egen asset = rowtotal(fa_lt fa_st) // sum short and long term liab together
sort yearf wave
by yearf wave: egen asset_q3 = xtile(asset) if !missing(asset), nq(3)   
g asset_q3_low = (asset_q3==1)
g asset_q3_mid = (asset_q3==2)
g asset_q3_high = (asset_q3==3)
label var asset_q3_low "Low Assets"
label var asset_q3_mid "Mid Assets"
label var asset_q3_high "High Assets"

cap drop gig_yesno_m
gen gig_yesno_m = gig_yesno
replace gig_yesno_m = 0 if (year==2021)&(wave>1)&((gig_recent_time !="")|(gig_ever!=.))
replace gig_yesno_m = 1 if (year==2021)&(wave>1)&(gig_recent_time !="")&((gig_recent_time == "3 to 6 months ago")|(gig_recent_time == "6 to 12 months ago")|(gig_recent_time == "Within the last 3 months"))
label var gig_yesno_m "Gig"

label var health_selfcompare "Health Physical"
label var health_selfmental "Health Mental"
gen health_selfcompare_pp = health_selfcompare_6mo
replace health_selfcompare_pp = health_selfcompare_3mo if health_selfcompare_pp==.
gen health_selfmental_pp = health_selfmental_6mo
replace health_selfmental_pp = health_selfmental_3mo if health_selfmental_pp==.
label var health_selfcompare_pp "Health Phys PP (3/13/2020)"
label var health_selfmental_pp  "Health Mental PP (3/13/2020)"
gen health_selfcompare_delt = health_selfcompare - health_selfcompare_pp
gen health_selfmental_delt = health_selfmental - health_selfmental_pp
label var health_selfcompare_delt "Health Phys \(\Delta\)"
label var health_selfmental_delt  "Health Mental \(\Delta\)"
gen health_selfcompare_delt3m = health_selfcompare - health_selfcompare_3m
gen health_selfmental_delt3m = health_selfmental - health_selfmental_3m
label var health_selfcompare_delt3m "Health Phys \(\Delta\) 3M"
label var health_selfmental_delt3m  "Health Mental \(\Delta\) 3M"

replace covid_care = 0 if covid_symptom == 0
replace covid_positive = 0 if covid_test == 0

cap drop health_covidrisk_m health_covidrisk_sp_m 
gen health_covidrisk_m = health_covidrisk
replace health_covidrisk_m = 0 if (health_covidrisk_fam==0)&(year==2021)
gen health_covidrisk_sp_m = health_covidrisk_sp
replace health_covidrisk_sp_m = 0 if (health_covidrisk_fam==0)&(year==2021)

foreach v in pop2sqkm_wq10 fin_income_q10 {
forvalues i=1/9 {
	cap drop `v'_`i'
	gen `v'_`i' = 1*(`v' == `i') if `v' != .
	if "`v'"=="fin_income_q10" {
		label var `v'_`i' "Income Dec`i'"
	}
}
}

*Did you donate in the past year (comparable to gig_yesno for 2018-19)
cap drop gig_yesno_21 
gen gig_yesno_21 = 1*(gig_recent_time!="more than a year ago") if ((year==2021)&(wave>1)&(gig_recent_time!=""))
replace gig_yesno_21 = 0 if ((year==2021)&(wave>1)&(gig_recent_time==""))
tab gig_yesno_21 

cap drop emer_2k_no emer_2k_probnot emer_2k_maybe emer_2k_yes
gen emer_2k_no = 1*(emer_2k==1) if (emer_2k!=.)
gen emer_2k_probnot = 1*(emer_2k==2) if (emer_2k!=.)
gen emer_2k_maybe = 1*(emer_2k==3) if (emer_2k!=.)
gen emer_2k_yes = 1*(emer_2k==4) if (emer_2k!=.)
label var emer_2k_no "Emergency 2K? --No"
label var emer_2k_probnot "Emergency 2K? --Prob Not"
label var emer_2k_maybe "Emergency 2K? --Maybe"

gen plan_per_days = 1*(plan_per_m==1) if plan_per_m!=.
gen plan_per_weeks = 1*(plan_per_m==2) if plan_per_m!=.
gen plan_per_months = 1*(plan_per_m==3) if plan_per_m!=.
label var plan_per_days "Planning Horizon: Next few days"
label var plan_per_weeks "Planning Horizon: Next few weeks"
label var plan_per_months "Planning Horizon: Next few months"

*Winsorize financial income
gen fin_income_f = inc_agi if wave==1
replace fin_income_f = fin_income_m if year==2021
winsor2 fin_income_f, c(0 99) s("_w") by(year wave)
label var fin_income_f_w "Income"


global samples 	s1819
cap drop samp_2 samp_3
gen samp_2	= "IRSFFA" if (year<2021)&(year>2017)
replace samp_2 = "SEIC" if year==2021

cap drop samp_3
gen samp_3	= "IRSFFA 2018-19" if (year<2021)&(year>2017)
replace samp_3 = "SEIC 5/20" if (year==2021)&(wave==1)
replace samp_3 = "SEIC 8/20 - 5/21" if (year==2021)&(wave>1)

cap drop samp_3g
gen samp_3g	= 1 if (year<2021)&(year>2017)
replace samp_3g = 2 if (year==2021)&(wave==1)
replace samp_3g = 3 if (year==2021)&(wave>1)

g nonwhite = (white==0)
g female = (male==0)
g emp = (emp_ue==0)

gen fin_income_q10c_sq = fin_income_q10^2 if fin_income_q10!=.
gen fin_income_q10c_lte3 = 1*(fin_income_q10<4) if fin_income_q10!=.
gen fin_income_q10c_4to6 = 1*(fin_income_q10<7)*(fin_income_q10>3) if fin_income_q10!=.
label var fin_income_q10c_lte3 "Income Low"
label var fin_income_q10c_4to6 "Income Low-Mid"

gen fa_lt_gt0 = 1*(fa_lt>0) if fa_lt!=.  
gen fl_lt_gt0 = 1*(fl_lt>0) if fl_lt!=.
label var fa_lt_gt0 "Fin Asset LT gt0"
label var fl_lt_gt0 "Fin Liab LT gt0"

replace cred_score_poor = . if cred_score ==.
replace cred_score_mid = . if cred_score ==.

* emer_2k_no emer_2k_probnot emer_2k_maybe
gen emer_2k_no_probnot = ( (emer_2k_no==1) | (emer_2k_probnot==1) )
replace emer_2k_no_probnot=. if (missing(emer_2k_no) & missing(emer_2k_probnot) & missing(emer_2k_maybe) & missing(emer_2k_yes))
label var emer_2k_no_probnot "Handle $2k emergency - no"
*plan_per_days plan_per_weeks plan_per_months 
gen plan_ST = ( (plan_per_days==1) | (plan_per_weeks==1) )
replace plan_ST=. if (missing(plan_per_m))
label var plan_ST "Planning horizon - days or weeks"
*credhab_payfull credhab_carrybal credhab_min credhab_late credhab_miss  
gen cc_del = ( (credhab_late==1) | (credhab_miss==1) )
replace cc_del=. if (missing(credhab_carrybal) & missing(credhab_late) & missing(credhab_min) & missing(credhab_miss) & missing(credhab_payfull))
label var cc_del "Credit card delinquency"
label var resource400_cash "Cash"
label var resource400_paynext "Credit card (next due date)"
label var resource400_paytime "Credit card (pay over time)"
label var resource400_loan "Bank loan"
label var resource400_afs "Non-bank loan"
label var resource400_fam "Family"
label var resource400_sell "Sell something"
label var resource400_other "Other"
label var resource400_none "Cannot meet"
gen resource400_cc = (resource400_paynext==1 | resource400_paytime==1)
replace resource400_cc = . if (missing(resource400_paynext) & missing(resource400_paytime))
label var resource400_cc "Credit Card"

* education dummies
gen somecol = (educ==12)
replace somecol = . if missing(educ)
label var somecol "Some College"
gen highschool = (educ==8)
replace highschool = . if missing(educ)
label var highschool "Associate's Degree"
gen associates = (educ==0)
replace associates = . if missing(educ)
label var associates "High School Degree"
* income dummies (since income deciles are not directly interpretable in IRSFFA, which is focused on LMI)
gen income_lt10k = (fin_income_m2<10000) if !missing(fin_income_m2)
gen income_10_20k = (fin_income_m2<20000 & fin_income_m2>=10000) if !missing(fin_income_m2)
gen income_20_30k = (fin_income_m2<30000 & fin_income_m2>=20000) if !missing(fin_income_m2)
gen income_30_40k = (fin_income_m2<40000 & fin_income_m2>=30000) if !missing(fin_income_m2)
gen income_40_50k = (fin_income_m2<50000 & fin_income_m2>=40000) if !missing(fin_income_m2)
gen income_50_60k = (fin_income_m2<60000 & fin_income_m2>=50000) if !missing(fin_income_m2)
gen income_60_70k = (fin_income_m2<70000 & fin_income_m2>=60000) if !missing(fin_income_m2)
gen income_70_80k = (fin_income_m2<80000 & fin_income_m2>=70000) if !missing(fin_income_m2)
gen income_80_90k = (fin_income_m2<90000 & fin_income_m2>=80000) if !missing(fin_income_m2)
gen income_90_100k = (fin_income_m2<100000 & fin_income_m2>=90000) if !missing(fin_income_m2)
label var income_lt10k "Income <$10k"
label var income_10_20k "Income [$10k-20k)"
label var income_20_30k "Income [$20k-30k)"
label var income_30_40k "Income [$30k-40k)"
label var income_40_50k "Income [$40k-50k)"
label var income_50_60k "Income [$50k-60k)"
label var income_60_70k "Income [$60k-70k)"
label var income_70_80k "Income [$70k-80k)"
label var income_80_90k "Income [$80k-90k)"
label var income_90_100k "Income [$90k-100k)"
gen income_lt30k = (fin_income_m2<30000) if !missing(fin_income_m2)
gen income_30_60k = (fin_income_m2<60000 & fin_income_m2>=30000) if !missing(fin_income_m2)
gen income_60_90k = (fin_income_m2<90000 & fin_income_m2>=60000) if !missing(fin_income_m2)
gen income_gt90k = (fin_income_m2>=90000) if !missing(fin_income_m2)
label var income_lt30k "Income <$30k"
label var income_30_60k "Income [$30k-60k)"
label var income_60_90k "Income [$60k-90k)"
label var income_gt90k "Income >=$90k"
gen income_lt20k = (fin_income_m2<20000) if !missing(fin_income_m2)
gen income_20_40k = (fin_income_m2<40000 & fin_income_m2>=20000) if !missing(fin_income_m2)
gen income_gt40k = (fin_income_m2>=40000) if !missing(fin_income_m2)
label var income_lt20k "Income <$20k"
label var income_20_40k "Income [$20k-40k)"
label var income_gt40k "Income >$40k"

drop afs_all_any afs_all_num
egen afs_all_num = rowtotal(afs_auto afs_check afs_lns_any afs_order afs_pawn afs_payday afs_payroll afs_refund afs_rent afs_svc_any afs_wire)
g afs_all_any = (afs_all_num>0)

save "${path_md}/hfs_analysis.dta" , replace


/*-------------------------------------------
BEGIN DESCRIPTIVE RESULTS
-------------------------------------------*/

/* ++++++++++++	GLOBAL MACRO VARIABLES   ++++++++++++  */
global spec_cluster cbsa
global spec_fe	state_year yw  // stateg state_year
global samples 	s1819
global controls  $urban_c $inc_c $demo_c $pay_c $resp_c 
global urban_c sqkm comm_car_p cbsad  pop2sqkm_wq10_*
global inc_c pvf100_p hhinc_lt50k_c aid_p pubai_p 
global demo_c white_p educ_bach_p empt_ft_p
global pay_c payday_exp5k plasma_exp50
/* ++++++++++++++++++++++++++++++++++++++++++++++++++  */


/*-------------------------------------------
Descriptive statistics (TABLE A1)
-------------------------------------------*/

eststo clear
quietly eststo: estpost sum $ssvars  if samp_3g==1, detail
quietly eststo: estpost sum $ssvars if (samp_3g==2 | samp_3g==3) , detail
esttab using "${path_prt}/SummaryStats.${ttype}", cells("mean(fmt(3) label(Mean))  sd(fmt(3) label(StdDev)) count(label(N))") ///
	mgroups("IRSFFA 2018-19" "SEIC 5/20 - 5/21", pattern(1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	label nodepvar replace nonotes nonumber nomtitle nonotes ${toptions}



/*-------------------------------------------
Table 1: Multivariate regressions relating demographic traits to plasma donation, by survey
-------------------------------------------*/
eststo clear
use "${path_md}/hfs_analysis.dta" , clear

global resp_c age_lte35 male black hispanic married children_gt0 bach  income_lt20k  emp_pt emp_ue student_s   /* emp_ft  children_gt1 emp_pt student_pt  */

*Compare who donates plasma and that it is robust to demographic.
eststo clear
quietly eststo : reghdfe plas_any $resp_c $urban_c $inc_c $demo_c $pay_c , absorb($spec_fe) cluster($spec_cluster) 
estadd local SMP "Both"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)
quietly eststo : reghdfe plas_any $resp_c $urban_c $inc_c $demo_c $pay_c if s1819==1, absorb($spec_fe) cluster($spec_cluster) 
estadd local SMP "IRSFFA"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)
quietly eststo : reghdfe plas_any $resp_c $urban_c $inc_c $demo_c $pay_c if s21==1, absorb($spec_fe) cluster($spec_cluster) 
estadd local SMP "SEIC"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)

	esttab using "${path_prt}/OLS_demo.${ttype}", replace cells(b(star fmt(3)) se(par fmt(3))) star(* .10 ** .05 *** .01)  ///
	stats(SMP ZipCont StateYear YearWave N r ymean, label("Sample" "Geo Controls" "State-Year F.E." "Year-Wave F.E." "N" "AdjR2" "Y-mean") fmt(0 0 0 0 0 3 3)) ///
	order($resp_c) drop( $urban_c $inc_c $demo_c $pay_c _cons  )  compress label



/*-------------------------------------------
Figure A3: Multivariate regressions estimates relating financial condition to plasma donation,
payday borrowing, and gig work
Panel A. Predictive effect of credit, assets, and liabilities on outcomes
-------------------------------------------*/
* can't do SIEC because variables missing
eststo clear
use "${path_md}/hfs_analysis.dta" , clear

* THIS IS INDIV USED THROUGH REST OF ANALYSIS (HAS INCOME SPLIT INTO DECILES
global resp_c      age_lte35 male black hispanic married children_gt0 bach  fin_income_q10_* emp_pt emp_ue student_s  
global controls    $urban_c $inc_c $demo_c $pay_c $resp_c 
global finvars      cred_score_poor cred_score_good shock_any liab_q3_low liab_q3_high  own_home own_car asset_q3_low asset_q3_high


*Fin Assets / Liab
eststo clear
quietly eststo: reghdfe plas_any $finvars $controls if (s1819==1), absorb($spec_fe) cluster($spec_cluster)  
estadd local SMP "IRSFFA"
estadd local Indiv "Y"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)
quietly eststo: reghdfe afs_payday $finvars $controls if (s1819==1), absorb($spec_fe) cluster($spec_cluster)  
estadd local SMP "IRSFFA"
estadd local Indiv "Y"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)
quietly eststo: reghdfe gig_yesno_m $finvars $controls if (s1819==1), absorb($spec_fe) cluster($spec_cluster)  
estadd local SMP "IRSFFA"
estadd local Indiv "Y"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)

	esttab * using "${path_prt}/OLS_Financial.${ttype}", replace cells(b(star fmt(3)) se(par fmt(3))) star(* .10 ** .05 *** .01)  ///
	stats(SMP Indiv ZipCont StateYear YearWave N r ymean, label("Sample" "Indiv. Controls" "Geo Controls" "State-Year F.E." "Year-Wave F.E." "N" "AdjR2" "Y-mean") fmt(0 0 0 0 0 0 3 3)) ///
	order($finvars ) drop( $controls  _cons  )  compress label
	
	
	*REMOVE STAR AND PARENTHESES TO MORE EASILY TANSLATE TO EXCEL - 1.96*se to get CI in excel
	esttab * using "${path_prt}/OLS_Financial.${ttype}", replace cells(b(fmt(3)) se(fmt(3)))   ///
	stats(SMP Indiv ZipCont StateYear YearWave N r ymean, label("Sample" "Indiv. Controls" "Geo Controls" "State-Year F.E." "Year-Wave F.E." "N" "AdjR2" "Y-mean") fmt(0 0 0 0 0 0 3 3)) ///
	order($finvars ) drop( $controls  _cons  )  compress label
	
/*-------------------------------------------
Figure A3: Multivariate regressions estimates relating financial condition to plasma donation,
payday borrowing, and gig work
Panel B. Predictive effect of access to different emergency financial resources on outcomes
-------------------------------------------*/
eststo clear
use "${path_md}/hfs_analysis.dta" , clear

global resp_c      age_lte35 male black hispanic married children_gt0 bach  fin_income_q10_* emp_pt emp_ue student_s  
global controls    $urban_c $inc_c $demo_c $pay_c $resp_c 
global resource 	resource400_none resource400_cash  resource400_loan resource400_cc resource400_afs  resource400_sell resource400_fam resource400_other  
*Emergency Funds
eststo clear
quietly eststo: reghdfe plas_any $resource $controls if (s1819==1), absorb($spec_fe) cluster($spec_cluster)  
estadd local SMP "IRSFFA"
estadd local Indiv "Y"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)
quietly eststo: reghdfe afs_payday $resource $controls if (s1819==1), absorb($spec_fe) cluster($spec_cluster)  
estadd local SMP "IRSFFA"
estadd local Indiv "Y"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)
quietly eststo: reghdfe gig_yesno_m $resource $controls if (s1819==1), absorb($spec_fe) cluster($spec_cluster)  
estadd local SMP "IRSFFA"
estadd local Indiv "Y"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)
	esttab * using "${path_prt}/OLS_400Emergency.${ttype}", replace cells(b(star fmt(3)) se(par fmt(3))) star(* .10 ** .05 *** .01)  ///
	stats(SMP Indiv ZipCont StateYear YearWave N r ymean, label("Sample" "Indiv. Controls" "Geo Controls" "State-Year F.E." "Year-Wave F.E." "N" "AdjR2" "Y-mean") fmt(0 0 0 0 0 0 3 3)) ///
	order($resource) drop( $controls  _cons  )  compress label	

	*REMOVE STAR AND PARENTHESES TO MORE EASILY TANSLATE TO EXCEL - 1.96*se to get CI in excel
	esttab * using "${path_prt}/OLS_400Emergency.${ttype}", replace cells(b(fmt(3)) se(fmt(3))) star(* .10 ** .05 *** .01)  ///
	stats(SMP Indiv ZipCont StateYear YearWave N r ymean, label("Sample" "Indiv. Controls" "Geo Controls" "State-Year F.E." "Year-Wave F.E." "N" "AdjR2" "Y-mean") fmt(0 0 0 0 0 0 3 3)) ///
	order($resource) drop( $controls  _cons  )  compress label	
	
		
	
/*-------------------------------------------
Table 2: Percentage of plasma donors by reason for donating and frequency
-------------------------------------------*/
eststo clear
use "${path_md}/hfs_analysis.dta" , clear
keep if !missing(plas_numc)
keep if plas_any==1
keep if s1819==1
replace plas_why = 5 if plas_why==7
replace plas_numc = . if plas_any==0
cap drop plas_numcg
gen plas_numcg = "1" if (plas_numc<=1) // the survey was coded such that 0 = 1
replace plas_numcg = "2-5" if (plas_numc<6)&(plas_numc>1) // infrequent defined as fewer than 6 donations 
replace plas_numcg = "6-10" if (plas_numc<11)&(plas_numc>5)
replace plas_numcg = ">10" if (plas_numc>10) // bc in 2018 over 10 was binned. in 2019 it was continuous

tabulate plas_why plas_numcg 
eststo clear
quietly estpost tabulate plas_why plas_numcg 
esttab using "${path_prt}/WhyDonatePlasma.${ttype}",  ///
		cell(colpct(fmt(2)) b(fmt(g) par keep(Total))) ///
		collabels(none) varlabels(`e(labels)') unstack ///
		mgroups("Donations in past 6 months", pattern(1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		noobs nonumber nomtitle nonotes replace ${toptions}


* Figure A2: Histogram of the frequency of plasma donation within the 6 months before survey response
eststo clear
use "${path_md}/hfs_analysis.dta" , clear
keep if !missing(plas_numc)
keep if plas_any==1
keep if s1819==1
keep if year==2019
tab plas_num
su plas_num



/*-------------------------------------------
Table A6: Mean of reasons for not working a gig job, by plasma donor status
-------------------------------------------*/
eststo clear
use "${path_md}/hfs_analysis.dta" , clear
keep if !missing(gig_whyno)
gen gig_whyno_time = (gig_whyno=="Do not have the time")
gen gig_whyno_cost = (gig_whyno=="cannot afford to pay costs of workin in the gig economy") 
gen gig_whyno_skill = (gig_whyno=="do not have skills required") 
gen gig_whyno_need = (gig_whyno=="don't need extra money") 
gen gig_whyno_other = (gig_whyno=="Other") 
label var gig_whyno_time "No time"
label var gig_whyno_cost "Too costly to enter"
label var gig_whyno_skill "Insufficient Skill"
label var gig_whyno_need "Don't need the money"
label var gig_whyno_other "Other"

*TTest Comparison.
global gig gig_whyno_time gig_whyno_cost gig_whyno_skill gig_whyno_need gig_whyno_other
global fn_gig "This table compares the why people choose not to pursue gig work by whether they donate plasma."

eststo clear
*Get means for donors
quietly estpost sum $gig if plas_any==1 & $samples==1
matrix meanf1=e(mean)
*matrix list meanf1
*Get means for non-donors
quietly estpost sum $gig if plas_any==0 & $samples==1
matrix meanf0=e(mean)
*matrix list meanf0
*Run the ttest
quietly estpost ttest $gig if $samples==1, by(antiplasma)
*Put it all together
quietly estadd matrix meanf0
quietly estadd matrix meanf1
esttab using "${path_prt}/TTest_gig_s($samples).${ttype}", ///
			noobs cells("meanf0(fmt(4)) meanf1(fmt(4)) b(star fmt(3)) se(fmt(3)) count(fmt(0))") star(* 0.1 ** .05 *** 0.01) ///
			collabels("Mean(Plasma Donors=0)" "Mean(Plasma Donors=1)" "Diff." "Std. Error" "Obs.") ///
			subs("cbsa" "CBSA") label dep gap  nonumber nonotes nomtitle replace  ${toptions}

		

/*-------------------------------------------
Table A4: Relationship between proximity and plasma donation, survey data
-------------------------------------------*/
eststo clear
use "${path_md}/hfs_analysis.dta" , clear
global resp_c      age_lte35 male black hispanic married children_gt0 bach  fin_income_q10_* emp_pt emp_ue student_s  
global controls    $urban_c $inc_c $demo_c $resp_c // $pay_c << Don't control for num plasma and payday nearby, since part of key explanatory

eststo clear
quietly eststo: reghdfe plas_any plasma_ind50  $controls if $samples==1 , absorb($spec_fe) cluster($spec_cluster) 
estadd local SMP "IRSFFA"
estadd local Indiv "Y"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)
quietly eststo: reghdfe plas_any plasma_ind100 $controls if $samples==1 , absorb($spec_fe) cluster($spec_cluster) 
estadd local SMP "IRSFFA"
estadd local Indiv "Y"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)
quietly eststo: reghdfe plas_any plasma_ind50 plasma_exp100  $controls if $samples==1 , absorb($spec_fe) cluster($spec_cluster) 
estadd local SMP "IRSFFA"
estadd local Indiv "Y"
estadd local ZipCont "Y"
estadd local StateYear "Y"
estadd local YearWave "Y"
estadd ysumm
estadd scalar r = e(r2_a)

	esttab * using "${path_prt}/OLS_Proximity.${ttype}", replace cells(b(star fmt(3)) se(par fmt(3))) star(* .10 ** .05 *** .01)  ///
	stats(SMP Indiv ZipCont StateYear YearWave N r ymean, label("Sample" "Indiv. Controls" "Geo Controls" "State-Year F.E." "Year-Wave F.E." "N" "AdjR2" "Y-mean") fmt(0 0 0 0 0 0 3 3)) ///
	order(plasma_ind50 plasma_ind100 plasma_exp100 ) drop( $controls  _cons  )  compress label	
	
	


/*-------------------------------------------
Table A5: Mean of demographic traits, by donation status and frequency
-------------------------------------------*/
* PLASMA VS NOPLASMA
eststo clear
use "${path_md}/hfs_analysis.dta" , clear
keep if !missing(plas_any)
replace plas_numc = 0 if plas_any==0
keep if !missing(plas_numc)
keep if s1819==1
gen plas_freq = (plas_numc>5)

*TTest Comparison.
global  sociodemo age_lte35 male black hispanic married children_gt0 singleparent bach somecol associates highschool ///
		income_lt10k income_10_20k income_20_30k income_30_40k income_40_50k emp_ft emp_pt emp_ue student_s  afs_all_any afs_payday

eststo clear
*Get means for donors
quietly estpost sum $sociodemo if plas_any==1 & $samples==1
matrix meanf1=e(mean) // donor
*matrix list meanf1
*Get means for non-donors
quietly estpost sum $sociodemo if plas_any==0 & $samples==1
matrix meanf0=e(mean) // non-donor
*matrix list meanf0
*Run the ttest
quietly estpost ttest $sociodemo if $samples==1, by(antiplasma)
*Put it all together
quietly estadd matrix meanf0 // non-donor
quietly estadd matrix meanf1 // donor
esttab using "${path_prt}/TTest_sociodemo_any.${ttype}", ///
			noobs cells("meanf0(fmt(4)) meanf1(fmt(4)) b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.1 ** .05 *** 0.01) ///
			collabels("Non-donors=0)" "Mean(Donors)" "Diff." "Std. Error" "Obs.") ///
			subs("cbsa" "CBSA") label dep gap  nonumber nonotes nomtitle replace  ${toptions}
			

* FREQ PLASMA VS INFREQ PLASMA
eststo clear
use "${path_md}/hfs_analysis.dta" , clear
keep if !missing(plas_any)
replace plas_numc = . if plas_any==0
keep if !missing(plas_numc)
keep if s1819==1
gen plas_freq = (plas_numc>5)
drop if plas_any==0 // keep only donors

*TTest Comparison.
global  sociodemo age_lte35 male black hispanic married children_gt0 singleparent bach somecol associates highschool ///
		income_lt10k income_10_20k income_20_30k income_30_40k income_40_50k emp_ft emp_pt emp_ue student_s  afs_all_any afs_payday

eststo clear
quietly estpost sum $sociodemo if plas_freq==0 & $samples==1
matrix meanf0=e(mean) //  infreq donor
quietly estpost sum $sociodemo if plas_freq==1 & $samples==1
matrix meanf1=e(mean) // freq donors
*matrix list meanf0
*Run the ttest
quietly estpost ttest $sociodemo if $samples==1, by(plas_freq)
*Put it all together
quietly estadd matrix meanf0 //  infreq donor
quietly estadd matrix meanf1 // freq donors
esttab using "${path_prt}/TTest_sociodemo_donfreq.${ttype}", ///
			noobs cells("meanf0(fmt(4)) meanf1(fmt(4)) b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.1 ** .05 *** 0.01) ///
			collabels("Mean(Infreq Plasma Donors=1)" "Mean(Freq Plasma Donors=1)" "Diff." "Std. Error" "Obs.") ///
			subs("cbsa" "CBSA") label dep gap  nonumber nonotes nomtitle replace  ${toptions}
		
	
